package com.cuiweiyou.bluemesh.bluetooth;

import com.cuiweiyou.bluemesh.model.LightModel;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class BluetoothStateTool {
    public static void flushOfflineState(Map<String, List<LightModel>> map) {
        Iterator<String> groups = map.keySet().iterator();
        while (groups.hasNext()) {
            String group = groups.next();
            List<LightModel> lightList = map.get(group);
            for (int i = 0; i < lightList.size(); i++) {
                LightModel lightModel = lightList.get(i);
                long lastLiveTime = lightModel.getLastLiveTime();
                long now = System.currentTimeMillis();
                if (now - lastLiveTime > 1000 * 30) { // 30秒没出现视为掉线
                    lightModel.setOnline(false);
                } else {
                    lightModel.setOnline(true);
                }
            }
        }
    }
}
